<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-police__policereport}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.keyWord" placeholder="报案人/报案标题" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-select v-model="dataForm.reportType" clearable placeholder="请选择案件类型">
            <el-option
              v-for="item in reportTypeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="creatorName" label="报案人" header-align="center" align="center" width="100"></el-table-column>
        <el-table-column prop="reportType" label="案件类型" header-align="center" align="center" width="100">
            <template slot-scope="scope">
                <el-tag v-if="scope.row.reportType == 0" size="small" type="info">刑事案件</el-tag>
                <el-tag v-else-if="scope.row.reportType == 1" size="small" type="success">民事案件</el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="title" label="报案标题" header-align="center" align="center"></el-table-column>
        <el-table-column prop="content" label="报案详情" header-align="center" align="center" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">点击查看详情</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" header-align="center" align="center" width="100">
            <template slot-scope="scope">
                <el-tag v-if="scope.row.status == 0" size="small" type="info">待处理</el-tag>
                <el-tag v-else-if="scope.row.status == 1" size="small" type="success">审核已通过</el-tag>
                <el-tag v-else-if="scope.row.status == 2" size="small" type="warning">审核未通过</el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="registerStatus" label="立案状态" header-align="center" align="center" width="100">
            <template slot-scope="scope">
                <el-tag v-if="scope.row.registerStatus == 0" size="small" type="info">未立案</el-tag>
                <el-tag v-else-if="scope.row.registerStatus == 1" size="small" type="success">已立案</el-tag>
            </template>
        </el-table-column>
        <el-table-column prop="createDate" label="报案时间" header-align="center" align="center" width="170"></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status == 0" type="text" size="small" @click="approvedReport(scope.row.id)">审核通过</el-button>
            <el-button v-if="scope.row.status == 0" type="text" size="small" @click="reviewFailedReport(scope.row.id)">审核不通过</el-button>
            <el-button v-if="scope.row.status == 1 && scope.row.registerStatus == 0" type="text" size="small" @click="caseReport(scope.row.id)">立即立案</el-button>
            <el-tag v-if="scope.row.status == 1 && scope.row.registerStatus == 1" type="success">该案件已立案，前往案件管理处查看</el-tag>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './policereport-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/police/policereport/page',
        getDataListIsPage: true,
        exportURL: '/police/policereport/export',
        deleteURL: '/police/policereport',
        deleteIsBatch: true
      },
      dataForm: {
        id: '',
        keyWord: '',
        reportType: ''
      },
      reportTypeOptions: [
        {
          label: '刑事案件',
          value: 0
        },
        {
          label: '民事案件',
          value: 1
        }
      ]
    }
  },
  components: {
    AddOrUpdate
  },
  methods: {
     // 审核通过
     approvedReport(id) {
      this.$http.put('/police/policereport', {
        id: id,
        status: 1
      }).then(({ data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.getDataList()
      })
    },
    // 审核不通过
    reviewFailedReport(id) {
      this.$http.put('/police/policereport', {
        id: id,
        status: 2
      }).then(({ data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.getDataList()
      })
    },
    // 立即立案
    caseReport(id) {
      this.$http.put('/police/policereport', {
        id: id,
        registerStatus: 1
      }).then(({ data: res}) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.getDataList()
      })
    },
  }
}
</script>
